﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using EFEntity;
using ISerives;
using Model;

namespace Serives
{
    public class salary_grant_details_Serives : Isalary_grant_details_Serives
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;

        public salary_grant_details_Serives(MyDbContext myDbContext,IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        public async Task<int> Add(Esalary_grant_details egd)
        {
          await myDbContext.Esgd.AddAsync(egd);
            return myDbContext.SaveChanges();
        }

        public Task<int> Del(int id)
        {
            throw new NotImplementedException();
        }

        public Task<List<salary_grant_details>> Select()
        {
            throw new NotImplementedException();
        }

        public async Task<Esalary_grant_details> Select_id(string id)
        {
            Esalary_grant_details list = new Esalary_grant_details();
            await Task.Run(() => {
                Esalary_grant_details list2 = myDbContext.Esgd.Where(e => e.salary_grant_id == id).FirstOrDefault();
                list = mapper.Map<Esalary_grant_details>(list2);
            });
            return list;
        }

        public async Task<List<Esalary_grant_details>> Select_name(string id)
        {
            List<Esalary_grant_details> list = new List<Esalary_grant_details>();
           await Task.Run(() => {
                List<Esalary_grant_details> list2 = myDbContext.Esgd.Where(e => e.salary_grant_id == id).ToList();
                list = mapper.Map<List<Esalary_grant_details>>(list2);
            });
            return list;
        }

        public async Task<int> Upd(Esalary_grant_details egd)
        {
           Esalary_grant_details me= myDbContext.Esgd.Where(e => e.grd_id == egd.grd_id).FirstOrDefault();
            me.bouns_sum = egd.bouns_sum; //: 奖励金额
           me.sale_sum = egd.sale_sum;       //: 销售绩效金额
            me.deduct_sum = egd.deduct_sum;        //: 应扣金额
          /*  me.salary_standard_sum = egd.; //: 标准薪酬总额*/
            me.salary_paid_sum = egd.salary_paid_sum;  //: 实发薪酬总额
            return await myDbContext.SaveChangesAsync();
        }
    }
}
